<template>
  <div>
    <div class="top-info">
      <div class="info-cont">
        <span class="fl info-link"
          ><i class="el-icon-message-solid" style="margin-right: 10px"></i
          >查政策，找服务，就上鲲鹏产业数字化服务平台！</span
        >
        <span class="fr" v-if="SignStatus">
          <i class="el-icon-user-solid" style="margin-right: 10px"></i
          ><span style="cursor: pointer" @click="SingOn">登录</span>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<span style="cursor: pointer" @click="Reg">注册</span>
        </span>
        <span class="fr" v-else>
          <img
            :src="userPhoto"
            alt=""
            class="user-photo"
            @click="ToUserCenter()"
          />
          <span class="user-name" @click="ToUserCenter()">{{ userName }}</span>
          <span style="cursor: pointer" @click="SingOut">退出</span>
        </span>
      </div>
    </div>
    <Sign :dialogFormVisible="status" @closepop="ClosePop" />
    <Reg :dialogFormVisible="statusReg" @closepop="ClosePopReg" />
  </div>
</template>

<script>
import Sign from "../components/Sign";
import Reg from "../components/Reg";
export default {
  name: "TopInfo",
  data() {
    return {
      status: false,
      statusReg: false,
      SignStatus: true,
      userPhoto: "",
      userName: "",
    };
  },
  components: {
    Sign,
    Reg,
  },
  methods: {
    SingOn() {
      this.status = true;
    },
    Reg() {
      this.statusReg = true;
    },
    ClosePop() {
      this.status = false;
    },
    ClosePopReg() {
      this.statusReg = false;
    },
    SingOut() {
      this.$cookies.remove("userdata");
      this.$cookies.remove("userinfo");
      this.$router.push({ name: "Home" });
      this.$router.go(0);
    },
    ToUserCenter() {
      this.$router.push({ name: "UserCenter" });
      this.$cookies.set("TopActive", 9);
    },
  },
  mounted() {
    // console.log(this.$cookies.get("userinfo"));
    if (this.$cookies.get("userdata")) {
      this.SignStatus = false;
      this.userPhoto = this.$cookies.get("userinfo").Photo;
      this.userName = this.$cookies.get("userinfo").NickName;
    } else {
      this.SignStatus = true;
    }
  },
};
</script>

<style scoped>
.top-info {
  height: 60px;
  line-height: 60px;
  background-color: #095aff;
  color: #fff;
  font-size: 14px;
  min-width: 1200px;
}
.info-cont {
  width: 1200px;
  margin: 0 auto;
}
.info-link {
  cursor: pointer;
}
.info-link:hover {
  text-decoration: underline;
}
.user-photo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  float: left;
  position: relative;
  top: 10px;
  margin-right: 10px;
}
.user-name {
  margin-right: 10px;
  cursor: pointer;
}
</style>
